//
//  TPAskAnswerRefreshView.m
//  ThePaperBase
//
//  Created by liubo on 2021/8/2.
//  Copyright © 2021 scar1900. All rights reserved.
//

#import "TPAskAnswerRefreshView.h"
#import <Masonry/Masonry.h>

@interface  TPAskAnswerRefreshView ()

///文案标题
@property (nonatomic, strong) UIButton *titleButton;
/// 指示图标
@property (nonatomic, strong) UIButton *indicatorIcon;

@end

@implementation TPAskAnswerRefreshView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
        [self setUpContraints];
    }
    return self;
}

- (void)setUpUI
{
    [self addSubview:self.titleButton];
    [self addSubview:self.indicatorIcon];
}

- (void)setUpContraints
{
    [self.titleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(50);
        make.left.mas_equalTo(self.indicatorIcon.mas_right).with.offset(0);
    }];
    
    [self.indicatorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(16);
    }];
}

- (void)setSelected:(BOOL)selected
{
    _selected = selected;
    self.titleButton.selected = selected;
    self.indicatorIcon.selected = selected;
}

#pragma mark - public
- (void)configTitle:(NSString *)title forState :(UIControlState)state
{
    [self.titleButton setTitle:title forState:state];
}

- (void)configTitleColor:(UIColor *)color forState:(UIControlState)state
{
    [self.titleButton setTitleColor:color forState:state];
}

- (void)configImage:(UIImage *)image forState:(UIControlState)state
{
    [self.indicatorIcon setImage:image forState:state];
}

#pragma mark - lazy load
- (UIButton *)titleButton
{
    if (!_titleButton) {
        _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_titleButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        _titleButton.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _titleButton;
}

- (UIButton *)indicatorIcon
{
    if (!_indicatorIcon) {
        _indicatorIcon = [UIButton buttonWithType:UIButtonTypeCustom];
        [_indicatorIcon setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _indicatorIcon;
}

@end
